package com.itdfq.shutdown;

import com.itdfq.shutdown.service.CustomShutDown;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class ShutdownApplication {


//    用于接受 shutdown 事件
    @Bean
    public CustomShutDown customShutDown(){
        return new CustomShutDown();
    }


    @Bean
    public ConfigurableServletWebServerFactory webServerFactory(CustomShutDown customShutDown){
        // TomcatServletWebServerFactory 是 Spring Boot 实现内嵌 Tomcat 的工厂类
//        提供了 Web 容器默认的公共实现，如应用上下文设置，会话管理等
        TomcatServletWebServerFactory tomcatServletWebServerFactory = new TomcatServletWebServerFactory();
        tomcatServletWebServerFactory.addConnectorCustomizers(customShutDown);
        return tomcatServletWebServerFactory;
    }

    public static void main(String[] args) {
        SpringApplication.run(ShutdownApplication.class, args);
    }

}
